package com.google.code.alpenglow.sample.ers.components.core;

import java.util.Set;

import com.google.code.alpenglow.sample.ers.components.SubscriberRegistry;
import com.google.code.alpenglow.sample.ers.domain.provider.Service;
import com.google.code.alpenglow.sample.ers.domain.topay.SearchContext;
import com.google.code.alpenglow.sample.ers.domain.topay.SearchCriteria;
import com.google.code.alpenglow.sample.ers.domain.topay.ServiceToPay;


public class SearchDispatcher {
	
	public SubscriberRegistry subscriberRepository;
	public ServiceRegistry serviceRegistry;
	public ConnectorDispatcher connectorDispatcher;

	public Set<ServiceToPay> search(SearchCriteria criteria, SearchContext context) {
		Set<Service> allowedServices = serviceRegistry.findAllowedServices(context, criteria);
		
		Set<ServiceToPay> results = subscriberRepository.search(criteria, allowedServices);
		results.addAll(connectorDispatcher.search(criteria, allowedServices));
		return results;
	}
}
